﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QUT.Bio.Util {
	
	/// <summary>
	/// A PopupOverlay is a simple canvas intended primarily to host popup windows and alerts
	/// as one layer (probably the uppermost) in a view.
	/// </summary>
	
	public class PopupOverlay: Canvas {
		
		/// <summary>
		/// Displays a window (provided by the consumer) with the specified dimensions.
		/// </summary>
		/// <param name="w">The window to display.</param>
		/// <param name="left">The horizontal position of the left edge of the window.</param>
		/// <param name="top">The vertical position of the top edge of the window.</param>
		/// <param name="width">The width (in pixels) of the window.</param>
		/// <param name="height">The height (in pixels) of the window.</param>
		
		public void ShowWindow ( PopupWindow w, double left, double top, double width, double height ) {
			w.Width = width;
			w.Height = height;
			w.Left = left;
			w.Top = top;

			if ( w.Container == null ) {
				w.Container = this;
			}
			else {
				w.ToFront();
			}
		}

		static int progressCounter = 0;
		const double progressAngle = Math.PI / 6;
		const double progressRadius = 75;

		/// <summary>
		/// Displays a simple progress window.
		/// </summary>
		/// <param name="text">The title to display on the popup progress window.</param>
		/// <param name="width">The desired width of the window.</param>
		/// <param name="height">The desired height of the window.</param>
		/// <returns>A reference to the progress window so the caller can close it when time comes.</returns>
		
		public SimpleProgressWindow CreateInfoWindow (
			string text,
			double width,
			double height
		) {
			SimpleProgressWindow window = new SimpleProgressWindow( text );

			ShowWindow( window,
				ActualWidth / 2 - width / 2 + progressRadius * Math.Sin( progressCounter * progressAngle ),
				ActualHeight / 2 - height / 2 - progressRadius * Math.Cos( progressCounter * progressAngle ),
				width,
				height
			);

			progressCounter++;

			return window;
		}
	}
}
